﻿using System;
using System.Windows.Forms;
using SQLDiagConfiguration.Properties;

namespace SQLDiagConfiguration
{
    /// <summary>
    /// This class provides the Instance Info specific implentations
    /// </summary>
    public partial class InstanceInfoPage : BasePage
    {
        #region Constructor
        public InstanceInfoPage(DiagInfoObject obj)
        {
            DiagInfo = obj;
            InitializeComponent();

        }
        #endregion Constructor

        #region Page specific override methods
        /// <summary>
        /// This method will load state from the configuration file
        /// and then enable elements based on values in the file
        /// </summary>
        public override void LoadState()
        {
            base.LoadState();
            bool blockEnable = chkBlockingCollector.Checked;
            txtBlockingFileCount.Enabled = blockEnable;
            txtBlockingMaxFileSize.Enabled = blockEnable;
            cbBlockingPollingInterval.Enabled = blockEnable;
            bool diagEnable = chkSQLDiagCollector.Checked;
            chkSQLDiagAtStartUp.Enabled = diagEnable;
            chkSQLDiagAtShutDown.Enabled = diagEnable;
        }
        public override void LoadControlText()
        {
            base.LoadControlText();
            chkSQLDiagCollector.Text = Resources.strchkSQLDiagCollector;
            chkSQLDiagAtStartUp.Text = Resources.strchkSQLDiagAtStartUp;
            chkSQLDiagAtShutDown.Text = Resources.strchkSQLDiagAtShutDown;
            chkBlockingCollector.Text = Resources.strchkBlockingCollector;
            lblBlockiingMaxFileSize.Text = Resources.strlblBlockiingMaxFileSize;
            lblBlockingMaxNumFiles.Text = Resources.strlblBlockingMaxNumFiles;
            lblBlockingPollingInterval.Text = Resources.strlblBlockingPollingInterval;
        }
        #endregion Page specific override methods

        #region Event Handlers
        /// <summary>
        /// Enable /disable based on whether or not SQLDiag Collection is enabled
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkSQLDiagCollector_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox cb = (CheckBox)sender;
            chkSQLDiagAtStartUp.Enabled = cb.Checked;
            chkSQLDiagAtShutDown.Enabled = cb.Checked;
        }
        /// <summary>
        /// Enable /disable based on whether or not Blocking Collection is enabled
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkBlockingCollector_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox cb = (CheckBox)sender;
            txtBlockingMaxFileSize.Enabled = cb.Checked;
            cbBlockingPollingInterval.Enabled = cb.Checked;
            txtBlockingFileCount.Enabled = cb.Checked;
        }
        #endregion Event Handlers
    }
}
